package com.apes.scm.masterdata.frame.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.product.model.ProductGroup;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：销售区域
 *
 * @author xul
 * @create 2018-03-08 10:56
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = SalesTerritories.CONST_TABLE_NAME, indexes = {
        @Index(columnList = "sales_org_id, product_group_id, channel_id", unique = true)
})
public class SalesTerritories extends Model {
    public static final String CONST_TABLE_NAME = "mas_sales_territories";

    @Id
    @Column(name = "id", length = 30)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "销售区域编码", prefix = "8")
    @Comment("编码")
    private String id;  //编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "sales_org_id", referencedColumnName = "id")
    @Comment("销售组织编码")
    private Organization salesOrg; //销售组织

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_group_id", referencedColumnName = "id")
    @Comment("商品组编码")
    private ProductGroup productGroup; //商品组

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "channel_id", referencedColumnName = "id")
    @Comment("渠道编码")
    private Channel channel; //渠道

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效标记")
    private boolean valid; //有效

}
